package cn.itcast.item.controller;

import cn.itcast.hmall.dto.common.PageDTO;
import cn.itcast.hmall.dto.common.ResultDTO;
import cn.itcast.hmall.pojo.item.Item;
import cn.itcast.hmall.pojo.item.PageSelectItem;
import cn.itcast.item.constants.MqConstants;
import cn.itcast.item.service.ItemService;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/item")
@RestController
public class ItemController {
    @Autowired
    private ItemService itemService;

    @PostMapping("/list")
    public PageDTO<Item> pageSelect(@RequestBody PageSelectItem item){
        return itemService.pageSelect(item);
    }
    @GetMapping("/{id}")
    public Item selectOne(@PathVariable("id") String id){
        return itemService.getById(id);
    }
    @PostMapping
    public ResultDTO addOne(@RequestBody Item item){
        itemService.save(item);
        return ResultDTO.ok();
    }
    @PutMapping("/status/{id}/{status}")
    public ResultDTO upDownUpdate(@PathVariable("id") Long id,@PathVariable("status") Integer status){
        return itemService.upDownUpdate(id,status);
    }
    @PutMapping
    public ResultDTO changeUpdate(@RequestBody Item item){
        return itemService.changeUpdate(item);
    }
    @DeleteMapping("/{id}")
    public ResultDTO itemDelete(@PathVariable("id") String id){
        itemService.removeById(id);
        return ResultDTO.ok();
    }
    @PutMapping("/add")
    public void addUpdate(@RequestBody Item item){
        itemService.addUpdate(item);
    }
}
